package com.nari.ysphd.ui;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.nari.ysphd.R;

import java.util.Timer;
import java.util.TimerTask;

import nari.mip.core.AppEntryActivity;
import nari.mip.core.Platform;
import nari.mip.core.PlatformConfig;

public class StartActivity extends AppEntryActivity {

    private static final String TAG = StartActivity.class.getSimpleName();

    @Override
    protected void preOnReady() {
        super.preOnReady();
        Log.d(TAG, "preOnReady: ");
        setContentView(R.layout.activity_start);
        Platform.getCurrent().setPlatformContext(getApplicationContext());
        PlatformConfig.getSingleton().setUseSsl(true);
        PlatformConfig.getSingleton().setUseValidateCode(true);
        PlatformConfig.getSingleton().setUseIntegrityCheck(true);
    }

    @Override
    protected void onReady(Bundle bundle) {
        Log.d(TAG, "onReady: " + Platform.getCurrent().getMembership().getCurrentUser().getUserName());
        Log.d(TAG, "onReady: getSystemID" + Platform.getCurrent().getMembership().getSystemID());
        Log.d(TAG, "onReady: getSystemName" + Platform.getCurrent().getMembership().getSystemName());
        Log.d(TAG, "onReady: getToken" + Platform.getCurrent().getMembership().getToken());
        Log.d(TAG, "onReady: getCurrentUser" + Platform.getCurrent().getMembership().getCurrentUser());
        startActivity(new Intent(StartActivity.this, LoginUI.class));
        finish();
    }


//		dpm = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);
//		componentName = new ComponentName(this, AdminReceiver.class);
//		if (dpm.isAdminActive(componentName)) {//判断超级管理员是否已激活
//			Log.d(TAG, "onCreate: " + true);
////			Process.killProcess(Process.myPid());
//		} else {
//			Log.d(TAG, "onCreate: " + false);
////            Process.killProcess(Process.myPid());
//            activeAdmin();
//		}


	/*
激活管理员页面
*/
//	public void activeAdmin() {
//		Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
//		intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);
//		intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "请激活超级管理员");
////		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//		startActivity(intent);
//	}


    private void delayStartingActivity() {
        final Timer timer = new Timer();
        final Intent intent = new Intent();
        intent.setClass(this, LoginUI.class);
        timer.schedule(new TimerTask() {
            public void run() {
                startActivity(intent);
                finish();
            }
        }, 2 * 1000);
    }

    private void autoLogin() {
        delayStartingActivity();

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        Platform.getCurrent().stop(MyApp.getApp());
    }
}


